package com.ifonly.plugin;

import com.ifonly.activerecord.Db;
import com.ifonly.activerecord.Model;
import com.ifonly.activerecord.providers.DataSourceProvider;
import com.ifonly.activerecord.providers.DruidDataSourceProvider;

/**
 * @author <a href="mailto:ifonlymaster@163.com">ifonly</a>
 * @version 1.0 2015-12-18 16:10
 * @since JDK 1.6
 */
public class ActiveRecordPlugin implements Plugin {
    private Db db = Db.getInstance();
    private DataSourceProvider dataSourceProvider;

    public ActiveRecordPlugin() {
        this(new DruidDataSourceProvider());
    }

    public ActiveRecordPlugin(DataSourceProvider dataSourceProvider) {
        this.dataSourceProvider = dataSourceProvider;
        db.init(dataSourceProvider);
    }

    public ActiveRecordPlugin addTableMapper(Class<? extends Model> clazz) {
        db.addTableMapper(clazz);
        return this;
    }

    @Override
    public boolean start() {
        db.buildTableModelMappers();
        return true;
    }

    @Override
    public boolean stop() {
        return true;
    }

}
